package com.iclient.job;

import java.util.ArrayList;
import java.util.List;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

import com.plugins.http.MyWbFollows;
import com.plugins.server.MQServer;

import weibo4j.Users;
import weibo4j.model.User;
import weibo4j.model.WeiboException;

@Repository
public class UnFollowUserJob {
	
	@Scheduled(cron="0 54 11 * * ?")
	public void execute() throws WeiboException, InterruptedException{
		String access_token = "2.00CcoeoBiVSGZBdf2439cd6bP7zdDC";
		String uid = "1664677310";
		Users um = new Users(access_token);
		User user = um.showUserById(uid);
		Integer count = user.getFriendsCount();
		Integer pageSize = count%10 == 0 ? count/10 : count/10 + 1;
		List<String> urls = new ArrayList<>();
		if(pageSize > 0){
			for(int i=1; i<=pageSize; i++){
				 urls.addAll(MyWbFollows.getFollows(i));
			}
			if(!CollectionUtils.isEmpty(urls)){
				MQServer mqServer = MQServer.getServer();
				for(String url : urls){
					mqServer.publishMsg("sina", "sina.weibo", "unfollow", url);
				}
			}
		}
		
	}
	
}
